package com.qf.fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.qf.adapter.MineAdapter;
import com.qf.homeproject.R;

public class MineFragment extends Fragment
{
	ListView lv;
	List<Map<String, Object>> datas = new ArrayList<Map<String, Object>>();
	MineAdapter adapter;
	static Bundle bundle;

	public static Fragment newInstance(String title)
	{
		MineFragment mineFrag = new MineFragment();
		bundle = new Bundle();
		bundle.putString("title", title);
		mineFrag.setArguments(bundle);
		return mineFrag;
	}

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		initData();
		initAdapter();
	}

	private void initAdapter()
	{
		adapter = new MineAdapter(getActivity(), datas);

	}

	private void initData()
	{
		String[] myInfo = getResources().getStringArray(R.array.mineinfo);
		TypedArray mineArray = getResources().obtainTypedArray(R.array.mineimg);
		Log.i("info", "资源数组已经初始化完毕");
		Map<String, Object> map = null;
		for (int i = 0; i < myInfo.length; i++)
		{
			map = new HashMap<String, Object>();
			map.put("info", myInfo[i]);
			map.put("img", mineArray.getDrawable(i));
			datas.add(map);
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState)
	{
		View view = inflater.inflate(R.layout.fragment_mine, null);
		lv = (ListView) view.findViewById(R.id.mine_listview_id);
		return view;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState)
	{
		lv.setAdapter(adapter);
		adapter.notifyDataSetChanged();
		super.onActivityCreated(savedInstanceState);
	}

}
